package com.wushibo.adddatabackend.service.impl;

import com.wushibo.adddatabackend.entity.User;
import com.wushibo.adddatabackend.mapper.UserMapper;
import com.wushibo.adddatabackend.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    /**
     * 登录
     * @param account
     * @param password
     * @return
     */
    @Override
    public String loginService(String account, String password) {
        User user = userMapper.login(account);
        if(user!=null){
            if(password.equals(user.getPassword())){
                System.out.println("登录成功，欢迎吴世博！！！UserServiceImpl");
                return "success";
            }else{
                return "密码错误";
            }
        }
        return "此用户不存在";
    }

    /**
     * 注册
     * @param user
     * @return
     */
    @Override
    public String registerService(User user) {
        User userE = userMapper.login(user.getAccount());
        if(userE==null){
            if("".equals(user.getPassword())) {
                return "请输入密码";
            }
//            }else if ("".equals(user.getName())){
//                return "请输入用户昵称";
//            }
            else {
                userMapper.insert(user);  //此处是使用MybatisPlus实现的！！
                return "SUCCESS";
            }
        }
        return "用户已存在";
    }
}
